<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8" />
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<title></title>

		<link rel="stylesheet" type="text/css" href="css/base.min.css" />
		<style>
			html,
			body {
				height: 100%;
				width: 100%;
			}
			
			.header{
				padding: 0;
			}
		</style>
	</head>

	<body>

		<header class="header header-transparent ">
			<ul class="nav tile-brand tile nav-justified waves-attach waves-light">
				<li>
					<a>appcanLoader</a>
				</li>
			</ul>
		</header>

		<div class="">
			<div class="">
				<div class="form-group form-group-label form-group-brand">
					<label class="floating-label" for=".url">请输入地址</label>
					<input class="form-control" id="url" type="text">
				</div>

				<button class="btn btn-brand waves-attach waves-light waves-effect" onclick="cleanCache();" tapmode>清除缓存</button>
				<!--<button class="mui-btn mui-btn-blue" onclick="func_scanurl();" tapmode>扫描网址</button>-->
				<button class="btn btn-brand waves-attach waves-light waves-effect" onclick="scanurl();" tapmode>扫描网址New</button>
				<button class="btn btn-brand waves-attach waves-light waves-effect" onclick="openurl();" tapmode>打开网址</button>
			</div>
		</div>
	</body>
	<!--<script type="text/javascript" src="./script/api.js"></script>-->
	<script src="js/appcan.js"></script>
	<script src="js/appcan.control.js"></script>
	<script type="text/javascript" src="js/jquery-2.2.1.min.js"></script>
	<script src="js/base.min.js"></script>
	<script type="text/javascript" src="rtc.js"></script>
	<script>
		appcan.ready(function() {
			var url = appcan.locStorage.getVal('url');
			if (url != null) {
				$('#url').val(url);
			}
			rtcInit();
			uexScanner.cbOpen = scanCB;
			uexWidgetOne.cbCleanCache = cbCleanCache;
		});

		function scanCB(opCode, dataType, data) {
			if (opCode) {
				toast('打开摄像头失败，请检查应用权限');
			} else {
				toast('扫描成功，点击打开网址进入');
				data=JSON.parse(data);
				alert(data.code);
				$('#url').val(data.code);
			}
		}

		function scanurl() {
			uexScanner.open();
			var jsonData = '{"tipLabel":"对准二维码,即可自动扫描","title":"扫一下"}';
			uexScanner.setJsonData(jsonData);
		}

		function cleanCache() {
//			alert(1);
			uexWidgetOne.cleanCache();
		}

		function cbCleanCache(opId,dataType,data) {
			if (data == 0) {
				toast("缓存清除成功！");
			} else {
				toast("非主widget不能清除Cache！");
			}
		}

		function openurl() {
			var url = $('#url').val();
			appcan.locStorage.setVal('url', url);
			var win = appcan.require('window');
			win.open({
				name: 'demo',
				dataType: 0,
				data: url
			});
		}

		function toast(info, t) {
			t = arguments[1] ? arguments[1] : 3000;
			$('body').snackbar({
				content: info,
				alive: t,
				show: function() {
				}
			});
		}
	</script>

</html>